package com.hejiale.lease.common.exception;

import com.hejiale.lease.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description: 全局异常处理
 * @author: HeJiale
 * @since 2025/3/17 下午2:31
 */
@ControllerAdvice//该注解会拦截所有Controller中的异常
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)//会处理所有类型的异常
    @ResponseBody
    public Result handle(Exception e){
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(LeaseException.class)
    @ResponseBody
    public Result error(LeaseException e){
        e.printStackTrace();
        return Result.fail(e.getCode(),e.getMessage());
    }
}
